package iedcyt.acute.controller.listeners.menu;


import java.util.HashMap;

import iedcyt.acute.businessServices.ViewLogger;
import iedcyt.acute.model.MenuModel;
import iedcyt.acute.view.MainMenu;
import iedcyt.acute.view.ViewUtils;

import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;

public class UpdateFisYearTableListener extends MenuCommonListener implements SelectionListener {

	public UpdateFisYearTableListener(MenuModel _model, MainMenu _view) {
		super(_model, _view);
		
	}

	@Override
	public void widgetDefaultSelected(SelectionEvent arg0) {
		// TODO Auto-generated method stub

	}

	
	public void widgetSelected(SelectionEvent arg0) {
		HashMap<String,String> beansDb = new HashMap<String,String>();
		String maesorgPath = ViewUtils.getInstance().fileDialog("Base de datos Mesorg", "Seleccione el fichero mdb de la base de datos maesorg", "*.mdb");
		if(!maesorgPath.isEmpty()){
			beansDb.put("maesorgDataSource", getPath("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=", maesorgPath));
			if (_model.changeDatabases(beansDb)){
				_model.updateFisYear();
			}else{
				ViewLogger.getInstance().error("No se han podido cambiar las rutas de las bases de datos");
			}

		}

	}

}
